{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Chrmgun"

// By ArtemQa146

const
    Render_S = 31@
    Render_R = 30@
    Render_O = 29@

    Clip_Model = 27@
    Clip_X = 26@
    Clip_Y = 25@
    Clip_Z = 24@
    addgunshell = 23@
    Weapon_ID = 25
end

0085: Render_S = 0@ // (int)
0085: Render_O = 1@ // (int)

        gosub @Visible_Weapon

            repeat
            wait 0
            if and
                not actor.Driving($PLAYER_ACTOR)
                02D8:   actor $PLAYER_ACTOR current_weapon == Weapon_ID
            then
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08C3: clear 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0A8C: write_memory 0x740CF0 size 4 value 0.0 virtual_protect 0 //0.30000001
                0A8C: write_memory 0x740CF8 size 4 value 0.0 virtual_protect 0 //0.44999999
                0E35: set_render_object_position Render_O 0 0 0

                if or
                    Actor.Animation($PLAYER_ACTOR) == "shotgun_fire"
                    Actor.Animation($PLAYER_ACTOR) == "shotgun_fire_poor"
                    Actor.Animation($PLAYER_ACTOR) == "shotgun_crouchfire"
                then
                    if Actor.Animation($PLAYER_ACTOR) == "shotgun_fire"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "shotgun_fire" time
                    end
                    if Actor.Animation($PLAYER_ACTOR) == "shotgun_fire_poor"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "shotgun_fire_poor" time
                    end
                    if Actor.Animation($PLAYER_ACTOR) == "shotgun_crouchfire"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "shotgun_crouchfire" time
                    end
                        if and
                            1@ >= 0.15
                            1@ <= 0.68
                        then
                            if
                                1@ >= 0.55
                            then
                                2@ = 0.535
                                0087: 4@ = 1@ // (float)
                                0063: 4@ -= 2@  // (float)
                                //4@ /= 1.2
                                4@ *= -1.0

                                2@ = 0.5495
                                0087: 5@ = 1@ // (float)
                                0063: 5@ -= 2@  // (float)
                                5@ /= 8.0
                                //5@ /= 2.0
                                //5@ *= -1.0

                                2@ = 0.5495
                                0087: 6@ = 1@ // (float)
                                0063: 6@ -= 2@  // (float)
                                //6@ /= 2.0
                                6@ /= 4.0
                                6@ *= -1.0
                                if
                                    1@ <= 0.60
                                then
                                    0E35: set_render_object_position Render_O 4@ 5@ 6@
                                    0087: 8@ = 4@ // (float)
                                    0087: 9@ = 5@ // (float)
                                    0087: 11@ = 6@ // (float)
                                    0087: 15@ = 4@ // (float)
                                    0087: 16@ = 5@ // (float)
                                    0087: 17@ = 6@ // (float)
                                    addgunshell = 0
                                else
                                    0E35: set_render_object_position Render_O 15@ 16@ 17@
                                    if
                                        1@ >= 0.65
                                    then
                                        addgunshell = 0
                                    end
                                    if and
                                        1@ < 0.65
                                        addgunshell == 0
                                    then
                                        0A96: 6@ = ped $PLAYER_ACTOR struct
                                        0D4E: 7@ = struct 6@ offset 0x718 size 1 //active weap slot
                                        6@ += 0x5A0
                                        7@ *= 0x1C
                                        005A: 6@ += 7@ //CWeapon
                                        0172: 4@ = actor $PLAYER_ACTOR Z_angle
                                        2@ = 0.0
                                        3@ = 0.0
                                        if or
                                            4@ > 315.0
                                            4@ < 45.0
                                        then
                                            2@ = 0.5
                                        else
                                            if and
                                                4@ > 135.0
                                                4@ < 225.0
                                            then
                                                2@ = -0.5
                                            else
                                                if and
                                                    4@ > 225.0
                                                    4@ < 315.0
                                                then
                                                    3@ = -0.5
                                                else
                                                    if and
                                                        4@ > 45.0
                                                        4@ < 135.0
                                                    then
                                                        3@ = 0.5
                                                    end
                                                end
                                            end
                                        end
                                        0D0B: get_actor $PLAYER_ACTOR bone 24 matrix_pointer_to 4@ // IF and SET
                                        0D0A: store_coords_to 10@ 11@ 12@ from_matrix 4@ with_offsets 0.162 0.021 0.098
                                        0A96: 20@ = ped $PLAYER_ACTOR struct
                                        0AA6: call_method 0x73A3E0 struct 6@ num_params 4 pop 0 0.30000001 2@v 10@v 20@
                                        //0x73A3E0 void __thiscall CWeapon::AddGunshell(CWeapon *this, CEntity *entity, CVector *position, CVector2D *direction, float size)
                                        addgunshell = 1
                                    end
                                end
                            end
                        end
                    end

            else
                break
            end
            until not player.Defined(0)
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08BD: set 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0A8C: write_memory 0x740CF0 size 4 value 0.30000001 virtual_protect 0 //0.30000001
                0A8C: write_memory 0x740CF8 size 4 value 0.44999999 virtual_protect 0 //0.44999999
            gosub @Hide_Weapon

0A93: terminate_this_custom_script



:Hide_Weapon
0E31: set_render_object_visible Render_S 0
0E31: set_render_object_visible Render_O 0
return

:Visible_Weapon
0E31: set_render_object_visible Render_S 1
0E31: set_render_object_visible Render_O 1
return
